const TOKEN_INFO_KEY = 'tokenInfo'

export function saveLoginInfo(data) {
    sessionStorage.setItem(TOKEN_INFO_KEY, JSON.stringify(data))
}

export function getTokenInfo() {
    let tokeInfo = sessionStorage.getItem(TOKEN_INFO_KEY);
    if(tokeInfo) {
        return JSON.parse(tokeInfo)
    } else {
        return {}
    }
}

export function getToken() {
    return getTokenInfo().token
}

export function getPlatformId() {
    return getTokenInfo().platformId || ''
}

export function getUsername() {
    return getTokenInfo().nickName || ''
}

export function getRoleNames() {
    return getTokenInfo().roleNames || ''
}

export function removeLoginInfo() {
    sessionStorage.removeItem(TOKEN_INFO_KEY)
}
